home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / images1a / form1.frm (.txt) next >
Encoding:
Visual Basic Form  |  1999-09-22  |  5.2 KB  |  134 lines

  1. VERSION 5.00
  2. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
  3. Begin VB.Form MenuForm 
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "Image Shaped Form Example"
  6.    ClientHeight    =   3210
  7.    ClientLeft      =   150
  8.    ClientTop       =   750
  9.    ClientWidth     =   4710
  10.    Icon            =   "Form1.frx":0000
  11.    LinkTopic       =   "Form2"
  12.    MaxButton       =   0   'False
  13.    Moveable        =   0   'False
  14.    ScaleHeight     =   3210
  15.    ScaleWidth      =   4710
  16.    StartUpPosition =   3  'Windows Default
  17.    Begin MSComDlg.CommonDialog CommonDialog1 
  18.       Left            =   120
  19.       Top             =   0
  20.       _ExtentX        =   847
  21.       _ExtentY        =   847
  22.       _Version        =   393216
  23.       CancelError     =   -1  'True
  24.    End
  25.    Begin VB.Menu mOptions 
  26.       Caption         =   "&Options"
  27.       Begin VB.Menu mChangeBackgroundPicture 
  28.          Caption         =   "Change Background &Picture"
  29.       End
  30.       Begin VB.Menu mInstructions 
  31.          Caption         =   "&Instructions"
  32.       End
  33.       Begin VB.Menu mSeparator 
  34.          Caption         =   "-"
  35.       End
  36.       Begin VB.Menu mExit 
  37.          Caption         =   "&Exit"
  38.       End
  39.    End
  40. Attribute VB_Name = "MenuForm"
  41. Attribute VB_GlobalNameSpace = False
  42. Attribute VB_Creatable = False
  43. Attribute VB_PredeclaredId = True
  44. Attribute VB_Exposed = False
  45. 'All variables must be declared
  46. Option Explicit
  47. 'This is the variable that will keep the memory
  48. 'address of the region
  49. Private hRgn As Long
  50. 'Constants declaration needed for the CommonDialog
  51. Private Const OFN_FILEMUSTEXIST = &H1000
  52. Private Const OFN_HIDEREADONLY = &H4
  53. Private Const OFN_LONGNAMES = &H200000
  54. Private Const OFN_NONETWORKBUTTON = &H20000
  55. Private Const OFN_PATHMUSTEXIST = &H800
  56. Private Const CC_FULLOPEN = &H2
  57. Private Const CC_SOLIDCOLOR = &H80
  58. Private Const CC_RGBINIT = &H1
  59. Private Const CC_ANYCOLOR = &H100
  60. Private Sub Form_Load()
  61.     Me.Move 0, 0, 4000, 690
  62. 'Set the transparent color to White, Create the region
  63. 'and modify the Forms Shape with it
  64.     CommonDialog1.Color = vbWhite
  65.     SetRegion
  66. 'Show the Shaped Form
  67.     ShapedForm.Show
  68. End Sub
  69. Private Sub Form_Unload(Cancel As Integer)
  70. 'Free the used memory by the Region and unload the Shaped
  71. 'Form
  72.     If hRgn Then DeleteObject hRgn
  73.     Unload ShapedForm
  74. End Sub
  75. Private Sub mChangeBackgroundPicture_Click()
  76.     On Error Resume Next
  77.     Err.Clear
  78.     With CommonDialog1
  79. 'Set the CommonDialog Open File options
  80.         .DialogTitle = "Please Select a Picture"
  81.         .Flags = OFN_FILEMUSTEXIST + OFN_HIDEREADONLY + OFN_LONGNAMES + OFN_NONETWORKBUTTON + OFN_PATHMUSTEXIST
  82.         .Filter = "All Picture Files|*.bmp;*.dib;*.gif;*.jpg;*.wmf;*.emf;*.ico;*.cur|Bitmaps (*.bmp;*.dib)|*.bmp;*.dib|GIF Images (*.gif)|*.gif|JPEG Images (*.jpg)|*.jpg|Metafiles (*.wmf;*.emf)|*.wmf;*.emf|Icons (*.ico;*.cur)|*.ico;*.cur|All Files (*.*)|*.*"
  83.         .ShowOpen
  84. 'Check if Cancel was pressed
  85.         If Err.Number = 32755 Then Exit Sub
  86. 'Set the CommonDialog Color Select options
  87.         .Flags = CC_FULLOPEN + CC_SOLIDCOLOR + CC_RGBINIT + CC_ANYCOLOR
  88.         .ShowColor
  89. 'Check if Cancel was pressed
  90.         If Err.Number = 32755 Then Exit Sub
  91.         On Error GoTo erro
  92. 'Make the Shaped Form invisible
  93.         ShapedForm.Visible = False
  94.         DoEvents
  95. 'Change the Forms Background Picture, Width and Height
  96. 'It's necessary that the forms dimensions are equal or
  97. 'bigger that the Picture ones.
  98.         ShapedForm.Picture = LoadPicture(.FileName)
  99.         ShapedForm.Width = ShapedForm.Picture.Width
  100.         ShapedForm.Height = ShapedForm.Picture.Height
  101. 'Set it's new Shape based on it's Background Picture and
  102. 'Transparent Color
  103.         SetRegion
  104.     End With
  105. erro:
  106. 'Error handler
  107.     If Err.Number <> 0 Then MsgBox "Error Number " & Err.Number & " : " & Err.Description, vbApplicationModal + vbCritical
  108. 'Make the Shaped Form visible
  109.     ShapedForm.Visible = True
  110. End Sub
  111. Private Sub mExit_Click()
  112. 'Unload the Menu Form
  113.     Unload Me
  114. End Sub
  115. Private Sub SetRegion()
  116. 'Free the memory allocated by the previous Region
  117.     If hRgn Then DeleteObject hRgn
  118. 'Scan the Bitmap and remove all transparent pixels from
  119. 'it, creating a new region
  120.     hRgn = GetBitmapRegion(ShapedForm.Picture, CommonDialog1.Color)
  121. 'Set the Forms new Region
  122.     SetWindowRgn ShapedForm.hwnd, hRgn, True
  123. End Sub
  124. Private Sub mInstructions_Click()
  125. 'Show a message box with a simple explanation
  126.     Dim Texto As String
  127.     Texto = "This is what really happens:" & vbCrLf & vbCrLf
  128.     Texto = Texto & "The Background Picture of the Form and a particular colour is passed to a function. Then, the Image is scanned and all pixels that have equal colour to the Transparent Colour are removed from the Image, creating a new virtual Image (a Region, to be exact) that will be used by the form. The smaller the picture is, the faster it is scanned." & vbCrLf & vbCrLf & vbCrLf
  129.     Texto = Texto & "Programmed by Pedro Lamas" & vbCrLf & "Copyright 
  130. 1997-1999 Underground Software" & vbCrLf & vbCrLf
  131.     Texto = Texto & "Home-Page (Dedicated to VB): www.terravista.pt/portosanto/3723/" & vbCrLf & "E-Mail: sniper@hotpop.com"
  132.     MsgBox Texto, vbApplicationModal + vbInformation, "Instructions"
  133. End Sub
  134.